import Vue from 'vue'
import Router from 'vue-router'
import MenuType from '@/utils/menuType'
// in development env not use Lazy Loading,because Lazy Loading too many pages will cause webpack hot update too slow.so only in production use Lazy Loading

/* layout */
import Layout from '../views/layout/Layout'
const _import = require('./import_' + process.env.NODE_ENV)
Vue.use(Router)

/**
  * icon : the icon show in the sidebar
  * hidden : if `hidden:true` will not show in the sidebar
  * redirect : if `redirect:noredirect` will not redirct in the levelbar
  * noDropdown : if `noDropdown:true` will not has submenu in the sidebar
  * meta : `{ role: ['admin'] }`  will control the page role
  **/
export const constantRouterMap = [
  { name: '404', path: '/404', component: _import('/404'), hidden: true },

  { name: '说明',
    path: '/',
    component: _import('/home'),
    hidden: false,
    icon: 'dashboard',
    type: MenuType.Link
  },

  {
    name: '功能列表',
    path: '/function',
    component: Layout,
    hidden: false,
    type: MenuType.Expandable,
    children:[
      { name: '做题',
    path: '/info/:id',
    component:  _import('/question/info'),
    hidden: false,
    type: MenuType.Link
  },
  { name: '错题',
    path: '/errors/:id',
    component: _import('/question/errors'),
    hidden: false,
    type: MenuType.Link
  },
  { name: '上传',
    path: '/upload',
    component: _import('/question/upload'),
    hidden: false,
    type: MenuType.Link
  },
  { name: '调试',
    path: '/deal',
    component: _import('/deal'),
    hidden: false,
    type: MenuType.Link
  }
    ]
  },
  
]

const router = new Router({
  base: `${process.env.customDir}`,
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
router.routes = constantRouterMap
/**
 * 路由配置
 * @type {Object}
 */
/**
 * push到指定的路由
 * @param  {String | Object} key   路由配置键
 * @param  {*} param 参数
 * @param  {String | Array} breadcrumb 自定义面包屑
 */
router.pushTo = function (key, param, breadcrumb) {
  // this.push(this.routesConfig.getRoute(key, param, breadcrumb))
}
/**
 * replace到指定的路由
 * @param  {String | Object} key   路由配置键
 * @param  {*} param 参数
 * @param  {String | Array} breadcrumb 自定义面包屑
 */
router.replaceBy = function (key, param, breadcrumb) {
  // this.replace(this.routesConfig.getRoute(key, param, breadcrumb))
}
/**
 * push到指定的带query路由
 * @param  {String | Object} key   路由配置键
 * @param  {Object} query 参数
 * @param  {String | Array} breadcrumb 自定义面包屑
 */
router.pushQueryTo = function (key, query, breadcrumb) {
  // this.push(this.routesConfig.getRouteWithQuery(key, query, breadcrumb))
}
/**
 * replace到指定的带query路由
 * @param  {String | Object} key   路由配置键
 * @param  {Object} query 参数
 * @param  {String | Array} breadcrumb 自定义面包屑
 */
router.replaceQueryBy = function (key, query, breadcrumb) {
  // this.replace(this.routesConfig.getRouteWithQuery(key, query, breadcrumb))
}


export default router

export const asyncRouterMap = [
  { path: '*', redirect: '/404', hidden: true }
]
